using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class InsurancePlanController : Controller
    {
		private readonly IInsuranceRepository insuranceRepository;
		private readonly IInsurancePlanRepository insuranceplanRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public InsurancePlanController() //: this(new InsuranceRepository(), new InsurancePlanRepository())
        {
            this.insuranceRepository = Registry.RepositoryFactory.GetInsuranceRepository();
            this.insuranceplanRepository = Registry.RepositoryFactory.GetInsurancePlanRepository();
        }

        public InsurancePlanController(IInsuranceRepository insuranceRepository, IInsurancePlanRepository insuranceplanRepository)
        {
			this.insuranceRepository = insuranceRepository;
			this.insuranceplanRepository = insuranceplanRepository;
        }

        //
        // GET: /InsurancePlan/

        public ViewResult Index()
        {
            return View(insuranceplanRepository.All);//Including(insuranceplan => insuranceplan.Insurance));
        }

        //
        // GET: /InsurancePlan/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(insuranceplanRepository.Find(id));
        }

        //
        // GET: /InsurancePlan/Create

        public ActionResult Create()
        {
			ViewBag.PossibleInsurances = insuranceRepository.All;
            return View();
        } 

        //
        // POST: /InsurancePlan/Create

        [HttpPost]
        public ActionResult Create(InsurancePlan insuranceplan)
        {
            if (ModelState.IsValid) {
                insuranceplanRepository.Create(insuranceplan);
                insuranceplanRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleInsurances = insuranceRepository.All;
				return View();
			}
        }
        
        //
        // GET: /InsurancePlan/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleInsurances = insuranceRepository.All;
             return View(insuranceplanRepository.Find(id));
        }

        //
        // POST: /InsurancePlan/Edit/5

        [HttpPost]
        public ActionResult Edit(InsurancePlan insuranceplan)
        {
            if (ModelState.IsValid) {
                insuranceplanRepository.Update(insuranceplan);
                insuranceplanRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleInsurances = insuranceRepository.All;
				return View();
			}
        }

        //
        // GET: /InsurancePlan/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(insuranceplanRepository.Find(id));
        }

        //
        // POST: /InsurancePlan/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var insurance = insuranceplanRepository.Find(id);
            insuranceplanRepository.Delete(insurance);
            insuranceplanRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

